<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

use function Hyperf\Support\env;

$default_formatter = [
    'class' => Monolog\Formatter\JsonFormatter::class,
    'constructor' => [
        'format' => null,
        'dateFormat' => 'Y-m-d H:i:s',
        'allowInlineLineBreaks' => true,
    ],
];
$default_constructor = [
    'filename' => BASE_PATH . '/runtime/logs/error.log',
    'level' => Monolog\Level::Error,
    'maxFiles' => 2,
];
$handler = [
    'class' => Monolog\Handler\RotatingFileHandler::class,
    'constructor' => $default_constructor,
    'formatter' => $default_formatter
];

$handlers = [];
$handlers[] = $handler;


//测试环境开启debug日志和错误日志 生产环境只开启错误日志
if (env('APP_ENV') !== 'production') {
    $handler['constructor']['filename'] = BASE_PATH . '/runtime/logs/debug.log';
    $handler['constructor']['level'] = Monolog\Level::Debug;
    $handlers[] = $handler;
}

return [
    'default' => [
        'handlers' => $handlers
    ],
    'custom' => [
        'handler' => [
            'class' => Monolog\Handler\RotatingFileHandler::class,
            'constructor' => [
                'filename' => BASE_PATH . '/runtime/logs/custom.log',
                'level' => Monolog\Level::Info,
                'maxFiles' => 5,
            ],
        ],
        'formatter' => [
            'class' => Monolog\Formatter\LineFormatter::class,
            'constructor' => [
                'format' => null,
                'dateFormat' => 'Y-m-d H:i:s',
                'allowInlineLineBreaks' => true,
            ],
        ],
    ],
];
